package com.action;

import com.from.Action;
import com.from.ActionFrom;
import com.utils.ActionMapping;
import com.utils.FullBeans;
import com.from.LoginActionFrom;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.Map;

/**
 * Created by Administrator on 2015/2/3.
 */
@WebServlet(name = "LoginServlet")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

      /*  String username = request.getParameter("username");
        String password = request.getParameter("password");
        System.out.println("aaaa"+username+"::::"+password);*/


        String loginhidden = request.getParameter("loginhidden");
        ActionFrom loginActionFrom = FullBeans.Full(loginhidden,request);


        System.out.println(loginActionFrom);

        String message;
        Action action = null;
       /* if (loginhidden.equals("com.from.LoginActionFrom")){

            action = new LoginAction();
            System.out.println(action);
            message= action.exexute(loginActionFrom);
            PrintWriter printWriter = response.getWriter();
            printWriter.print(message);
            printWriter.flush();
            printWriter.close();
        }*/

        Map<String ,String> map = ActionMapping.getMap();
        try
        {
            String actionName = map.get(loginhidden);
            Class clazz = Class.forName(actionName);
            action =(Action)clazz.newInstance();
            message= action.exexute(loginActionFrom);//接口回调
            PrintWriter printWriter = response.getWriter();
            printWriter.print(message);
            printWriter.flush();
            printWriter.close();

        }catch (Exception e){
            e.printStackTrace();
        }







    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        this.doPost(request,response);
    }
}
